<template>
  <div class="box2">
    <div class="top">
      <p class="title">年龄比例</p>
      <p class="bg"></p>
    </div>
    <div class="charts" ref="charts"></div>
  </div>
</template>

<script setup lang="ts">
import * as echarts from "echarts";
import { onMounted, ref } from "vue";
let charts = ref();

onMounted(() => {
  let $echart = echarts.init(charts.value);
  $echart.setOption({
    title: {
      left: "21%",
      top: "center",
      text: "本日总数",
      textStyle: {
        color: "#fff",
      },
    },
    tooltip: {
      trigger: "item",
    },
    legend: {
      orient: "vertical",
      right: 10,
      textStyle: {
        color: "#fff",
      },
      formatter: "{name}",
    },
    grid: { left: 0, right: 0, top: 0, bottom: 0 },
    series: [
      {
        name: "Access From",
        type: "pie",
        radius: ["40%", "70%"],
        avoidLabelOverlap: false,
        center: ["30%", "50%"],
        itemStyle: {
          borderRadius: 10,
          borderColor: "#fff",
          borderWidth: 2,
        },
        label: {
          show: true,
          position: "inside",
          formatter: "{c}%",
        },
        labelLine: {
          show: false,
        },
        data: [
          { value: 10, name: "10岁以下" },
          { value: 40, name: "10-15岁" },
          { value: 15, name: "15-20岁" },
          { value: 15, name: "20-25岁" },
          { value: 20, name: "25以上" },
        ],
      },
    ],
  });
});
</script>

<style scoped lang="scss">
.box2 {
  background-color: #fff;
  margin-top: 10px;
  background: url(../../images/dataScreen-main-lb.png) no-repeat;
  background-size: 100% 100%;

  .top {
    .title {
      color: white;
      font-size: 20px;
      margin-left: 20px;
      margin-top: 10px;
    }

    .bg {
      width: 68px;
      height: 7px;
      background: url(../../images/dataScreen-title.png) no-repeat;
      background-size: 100% 100%;
      margin-top: 10px;
      margin-left: 20px;
    }
  }

  .charts {
    width: 100%;
    height: 240px;
    margin: 0px 0px;
  }
}
</style>
